package com.lagou.controller;

import com.lagou.bean.UpLoadResult;
import com.lagou.service.FileUpLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/oss")
public class OssController {

    @Autowired
    private FileUpLoadService fileUpLoadService;

    @PostMapping("/upload")
    @ResponseBody
    public UpLoadResult upload(@RequestParam("file") MultipartFile multipartFile) {
        return fileUpLoadService.upload(multipartFile);
    }

    @RequestMapping("/download")
    @ResponseBody
    public String download(@RequestParam("objectName") String objectName) {
        String filePath = fileUpLoadService.download(objectName);
        return "文件已下载到本地：" + filePath;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(@RequestParam("objectName") String objectName) {
        fileUpLoadService.delete(objectName);
        return "文件已删除！";
    }

}
